import router from "@/router";
export default {
  state() {
    return {
      taglist: [{ title: "首页", path: "/index/indexabout" }]
    }

  },
  getters: {
    taglist(state) {
      return state.taglist
    }
  },
  mutations: {
    // 添加标签事件
    watchrouters(state, val) {
      if (val.meta.title==""||val.path=="/404"||val.path=="/index") {
        return
      }
      if (state.taglist.find(item=>item.path == val.path)) return
      state.taglist.push({ title:val.meta.title, path: val.path })
    },
    // 移除标签事件
    deletetag(state, e) {
      console.log(state.taglist,669);
      console.log( e,11111);
      if (state.taglist.length == e+1) {
        console.log(1);
        state.taglist.splice(e,1)
        router.push(state.taglist[e-1].path) 
      } else{
        state.taglist.splice(e,1)
        router.push(state.taglist[e].path) 
      }
    },
    // 刷新事件
    refresh(state, e) {
      console.log(e,"刷新的");
      // router.push('/index/refreshIndirect')
      // console.log("/index/refreshIndirect" + e.path );
      router.push(e.path ) 
    },
    // 关闭右侧标签事件
    rightClose(state, e) {
      console.log(e,"关闭右侧标签");
      if (state.taglist.length>=e.index+1) {
        let num = state.taglist.length-e.index+1
        state.taglist.splice(e.index+1,num)
        router.push(state.taglist[e.index].path)
      } else {
        
      }
    },

    // 全部关闭标签事件
    allClose(state, e) {
      state.taglist.splice(1,state.taglist.length-1)
      router.push("/index")

    },


  },
  actions: {
    // 添加标签事件
    watchrouters(contest, val) {
      contest.commit('watchrouters', val)
    },
    // 移除标签事件
    deletetag(contest, e){
        contest.commit('deletetag',e)
    },
    // 刷新事件
    refresh(contest, e){
        contest.commit('refresh',e)
    },
    // 关闭右侧标签事件
    rightClose(contest, e){
        contest.commit('rightClose',e)
    },
    // 关闭全部标签事件
    allClose(contest, e){
        contest.commit('allClose',e)
    },
  },
}